#define BLINKER_MIOT_LIGHT
#define BLINKER_WIFI
#include <Blinker.h>

char auth[] = "c04bc9378059";
char ssid[] = "Passion International Club";
char pswd[] = "703703703";
String comdata = "";
// 新建组件对象
BlinkerButton Button_door("btn-door");//按键的名称 开灯
int counter = 0;
int GPIO=0;//定义GPIO口用于控制继电器
// 按下按键即会执行该函数
void button_door_callback(const String & state) {
  if (state == "on") {
    Serial.print('0');
    delay(100);
    Button_door.print("on");
  }
  if (state == "off") {
    Serial.print('1');
    delay(100);
    Button_door.print("off");
  }  
}
// 如果未绑定的组件被触发，则会执行其中内容
void dataRead(const String & data)
{
  counter++;
}

void setup() {
  // 初始化串口
  Serial.begin(115200);
  //点灯启动
  Blinker.begin(auth, ssid, pswd);
  Blinker.attachData(dataRead);
  //按键回调绑定
  Button_door.attach(button_door_callback);         
}

void loop() {
  Blinker.run();
  while (Serial.available() > 0)  
  {
      comdata += char(Serial.read());
      delay(2);
  }
  if (comdata.length() > 0)
  {
      Serial.println(comdata);
      Blinker.print(comdata);
      comdata = "";
  }
}
